import * as React from "react";
import Modal from "antd/es/modal/Modal";
import {Button, Card, Col, Form, Input, InputNumber, notification, Row} from "antd";
import {
    IdcardOutlined,
    MailOutlined,
    PlusOutlined,
    UnorderedListOutlined,
    UserOutlined,
    WhatsAppOutlined
} from "@ant-design/icons";
import {fetchAllRole, updateRole} from "../../requests/RoleManageRequest";
import Checkbox from "antd/es/checkbox/Checkbox";
import {updateUser} from "../../requests/UserManageRequest";
import {updateBudget} from "../../requests/BudgetManageRequest";


export default class UpdateBudgetModal extends React.Component {

    constructor(props) {
        super(props);
        this.state = {
            isModalVisible: false,
            formRef: React.createRef(),
        };
        this.props.onRef(this)
    }


    showModal = () => {
        this.setState({
            isModalVisible: true
        })
    };

    handleCancel = () => {
        this.setState({
            isModalVisible: false
        })
    };

    handleOk = () => {

        if (!this.props.userName) {
            notification.error({message: "更新预算失败", description: "请在表格中选择预算之后进行更新！"});
            return
        }

        this.state.formRef.current.validateFields()
            .then(values => {
                values['userName'] = this.props.userName
                console.log("Begin to update budget with params:" + JSON.stringify(values))
                updateBudget(values).then(edpRole => {
                    notification.info({message: "更新预算成功", description: "更新用户" + edpRole.result.userName + "的预算成功"});
                })
                this.setState({
                    isModalVisible: false
                })
            })
            .catch(info => {
                console.log('Validate message:', info);
            });
    };


    render = () => {
        return (
            <Modal title={"更新用户" + this.props.userName+"的预算"} visible={this.state.isModalVisible} onOk={this.handleOk}
                   onCancel={this.handleCancel}>
                <Form name="basic" ref={this.state.formRef}
                      initialValues={{'roles': this.props.roles}}>

                    <Form.Item
                        label="增加预算金额" name="incAmount">
                        <InputNumber prefix={<PlusOutlined/>}  />
                    </Form.Item>


                    <Form.Item
                        label="修改备注" name="remark">
                        <Input prefix={<MailOutlined/>}/>
                    </Form.Item>
                </Form>
            </Modal>
        );
    }
}
